package com.yzt.message.conversation;

import android.content.Context;

import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

import io.rong.imkit.conversationlist.model.BaseUiConversation;

/**
 * 消息处理者容器
 */
public class ReceiptHandlerContainer {

    public static Context mContext;

    /**
     * 理论上来说应该都写在一个循环里,但是保不准有很多奇怪的任务,一直加在同一块代理,很容易混乱,不利于维护,
     */
    private final List<IReceiptHandler> mHandlers = new CopyOnWriteArrayList<>();

    public void registerMessageReceiptHandler(IReceiptHandler handler) {
        mHandlers.add(handler);
    }

    public void removeAll() {
        mHandlers.clear();
    }

    public void unRegisterMessageReceiptHandler(IReceiptHandler handler) {
        mHandlers.remove(handler);
    }

    private ReceiptHandlerContainer() {

    }

    public List<IReceiptHandler> getReceiptHandlerList() {
        return mHandlers;
    }

    public static ReceiptHandlerContainer getInstance() {
        return ReceiptHandlerContainerHolder.mSington;
    }

    private static class ReceiptHandlerContainerHolder {

        private static final ReceiptHandlerContainer mSington = new ReceiptHandlerContainer();
    }

    public void handleReceipts(List<BaseUiConversation> uiConversations) {
        for (IReceiptHandler handler : mHandlers) {
            handler.handleReceipt(uiConversations);
        }
    }
}
